/**
 * Created by zlq on 2017/9/30.
 */


var page = 1;
var id;


function doAjax(){
    $.ajax({
        url:'/crm/ddmGoodPropertyC/getList.json',
        dataType:'json',
        data:{
            token:localStorage.getItem('crmtoken'),
            page:page,
        },
        type:'post',
        success: function (data) {
            if(data.code==-1){
                window.parent.location.href="/crm/login.jsp"
            }
            if(data.code==0){
                alert(data.msg);
            }
            if(data.code==1){
                $('#record').html(data.recordsTotal);
                $('#withdraw-record').empty();
                for(var i=0;i<data.datas.length;i++){

                    $('<tr class="gradeA odd">'+
                        '<a href=""><td class="detailsId"   >'+data.datas[i].id+'</td></a>'+
                        '<td class="sorting_1">'+data.datas[i].name+'</td>'+
                        '<td class="center ">'+data.datas[i].label+'</td>'+
                        '</tr>').appendTo($('#withdraw-record'));
                }

            }
        }
    })
}

$(function(){
    doAjax();
})




//点击保存
$('#save').click(function(){
    $.ajax({
        url:'/crm/ddmGoodPropertyC/add.json',
        dataType:'json',
        data:{
            token:localStorage.getItem('crmtoken'),
            name:$('#name').val(),
            label:$('#label').val(),
        },
        type:'post',
        success:function(data){
            if(data.code==0){
                alert(data.msg)
                return;
            }
            if(data.code==-1){
                window.parent.location.href="/crm/login.jsp"
            }
            if(data.code==1){
                alert('创建成功');
                $('#myModal5').removeClass('fade in');
                $('#myModal5').addClass('fade');
                $('#myModal5').attr('aria-hidden',true);
                $('#myModal5').css('display','none');
                $('.modal-backdrop').css('display','none');
                $('#myModal5 input').val('');
                page=1;
                doAjax();
            }
        }
    })
})
